package com.tanhua.dubbo.api;

import com.tanhua.model.mongo.FocusUser;
import org.apache.dubbo.config.annotation.DubboService;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

@DubboService
public class FocusUserApiImpl implements FocusUserApi{
    @Autowired
    private MongoTemplate mongoTemplate;
    /*关注*/
    @Override
    public void saveFocusUser(FocusUser followUser) {
        followUser.setId(ObjectId.get());
        followUser.setCreated(System.currentTimeMillis());
       mongoTemplate.save(followUser);
    }
    /*取消关注*/
    @Override
    public void deleteFocusUser(Long userId, Long followUserId) {
        Query query=new Query(Criteria.where("userId").is(userId).and("followUserId").is(followUserId));
        mongoTemplate.remove(query,FocusUser.class);
    }
}
